<?php
class ContactForm_Model_DefaultModule extends Zend_Db_Table{
	protected $_name = 'default_module_to_page';
	protected $_primary = '';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	/* select demo */
	public function selectModuleByCodeInPage($code,$page_code)
	{// co dung
		$select = $this->select();
		$select->from('default_module_to_page');
		$select->setIntegrityCheck(false);
		$select->where('module_code = ?', $code);
		$select->where('page_code = ?', $page_code);
		$arr = $this->fetchAll($select);
		return $arr;
	}
	public function selectModuleBySortOrderInPage($sort_order,$page_code)
	{ // co dung
		$select = $this->select();
		$select->from('default_module_to_page');
		$select->setIntegrityCheck(false);
		$select->where('sort_order = ?', $sort_order);
		$select->where('page_code = ?', $page_code);
		$arr = $this->fetchAll($select);
		return $arr;
	}	
		
	/* update demo */
	public function updateModule($module_code,$page_code,$sort)
	{ // co dung
		$adapter = $this->getDefaultAdapter();
		try {	
				$adapter->beginTransaction();
				$where[] = $adapter->quoteInto('module_code  = ?', $module_code);
				$where[] = $adapter->quoteInto('page_code = ?', $page_code);
				$adapter->update('default_module_to_page',array('sort_order'=>$sort),$where);
				$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}
	
}